# 警告框(alert)元素交互
# 获取弹窗内的文本内容
# 点击弹窗的确定按钮

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time


def she():
    dr = webdriver.Chrome(service=Service('chromedriver.exe'))
    dr.maximize_window()
    dr.get('https://sahitest.com/demo/alertTest.htm')
    return dr


def run(dr):
    dr.find_element(By.XPATH, '/html/body/form/input[2]').click()
    time.sleep(2)
    # 获取弹窗内的文本内容
    print(dr.switch_to.alert.text)
    # 点击弹窗的确定按钮
    dr.switch_to.alert.accept()
    time.sleep(20)


if __name__ == '__main__':
    dr = she()
    run(dr)
